package com.sikaryofficial.backend.service.points;

import com.sikaryofficial.backend.constant.RedisCacheKey;
import com.sikaryofficial.backend.service.IPointsDetailStrategy;
import com.sikaryofficial.common.core.constant.PointRuleConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author : qinjinyuan
 * @desc : 自助评价积分服务
 * @date : 2023/10/31 19:02
 */
@Service(value = PointRuleConstant.EVALUATE + IPointsDetailStrategy.SUFFIX)
@Slf4j
public class EvaluateService extends AbstractPointService {
    /**
     * 更新积分明细数据
     *
     * @param sourceId
     * @param userId
     * @return
     */
    @Override
    public boolean updatePoints(Long sourceId, Long userId) {
        return false;
    }

    /**
     * 更新积分明细数据
     *
     * @param sourceId
     * @param userId
     * @param pointsDetailValue
     * @return
     */
    @Override
    public boolean updatePointsByInputValue(Long sourceId, Long userId, Integer pointsDetailValue, String param, String sourceName) {
        if (Objects.isNull(userId) || Objects.equals(userId, 0L)) {
            return false;
        }
        // 自助评价，当积分大于上限，则不继续增加积分
        boolean isOver = checkPointsOver(userId, PointRuleConstant.EVALUATE, RedisCacheKey.EVALUATE_POINTS_NUM);
        if (!isOver) {
            // 没有超，则可以继续更新积分
            this.increasePoints(sourceId, userId, PointRuleConstant.EVALUATE, sourceName);
            // 增加后，进行统计缓存设置
            this.afterIncrease(userId, RedisCacheKey.EVALUATE_POINTS_NUM);
        }
        return false;
    }
}
